package day08.Test2;

import java.util.Arrays;
import java.util.Scanner;

/*
    abcabcabc
 */
public class SubString_homework {
    public static void main(String[] args) {
        System.out.print("请输入字符串:");
        String input = new Scanner(System.in).nextLine();
        System.out.print("输入要查找的字符串: ");
        String subStr = new Scanner(System.in).nextLine();
        int[] arr = findIndexofSubString(input, subStr);
        //int index= input.indexOf(subStr);
        System.out.println(Arrays.toString(arr));
    }

    private static int[] findIndexofSubString(String input, String subStr) {
        int[] arr = new int[input.length()];
        int index = 0;
        int i = 0;
        while(true){
            index = input.indexOf(subStr, index);
            if(index == -1){
                break;
            }
            arr[i] = index;
            i++;
            index += i;
            if(index >= input.length()){
                break;
            }
        }
        return Arrays.copyOf(arr, i);
    }

}
